package service.server;

/**
 * This class represents an ongoing session between a client and the forum server.
 * Should always be used after checking the validate() method.
 * @author 
 *
 */
public class ForumClientSession {

	private int userID;
	private Integer[] arbitratorsId;
	
	// Used to indicate that the session is valid with all the required parameters
	private boolean valid; 
	
	public byte[][] userPublicKeys;
	
	/**
	 * ForumClientSession constructor, which gets only the server generated temporary id for the client.
	 * Notice this object has a 'valid' flag. Must be set once the arbitrator is settled.
	 * @param userID
	 */
	public ForumClientSession(int usrID, int numberOfPubKeys){
		valid = false;
		this.userID = usrID;
		this.arbitratorsId = null;
		this.userPublicKeys = new byte[numberOfPubKeys][];
	}
	
	/**
	 * Update the supervising arbitrator ID for this session
	 * @param id - arbitrator Id
	 */
	public void setArbitrators(Integer[] ids){
		this.arbitratorsId = ids;
	}
	
	/**
	 * Return the current session arbitrator id.
	 * @return arbitrator id
	 */
	public Integer[] getArbitrators(){
		return this.arbitratorsId;
	}
	
	public byte[][] getUserKey(){
		return this.userPublicKeys;
	}
	
	public void setUserPubKey(byte[][] key){
		this.userPublicKeys = key;
	}
	
	
	/**
	 * This method sets the 'valid' flag in case all the object fields are valid and set
	 * @return
	 */
	 public boolean validate(){
		//System.out.println("FORUM SERVER: clientid=" + userID + ", arbitrator=" + this.arbitratorsId);
		this.valid = (this.arbitratorsId!=null && this.userPublicKeys!=null) ? true : false;
		return this.valid;
	}
	
	
}
